using System;

namespace octalforty.Componento.Impl
{
    internal class ConsoleStylingScope : IDisposable
    {
        private ConsoleColor? oldForegroundColor;

        public ConsoleStylingScope(ConsoleColor? foregroundColor)
        {
            if(!foregroundColor.HasValue) 
                return;
            
            oldForegroundColor = Console.ForegroundColor;
            Console.ForegroundColor = foregroundColor.Value;
        }

        void IDisposable.Dispose()
        {
            if(oldForegroundColor.HasValue)
                Console.ForegroundColor = oldForegroundColor.Value;
        }
    }
}